//
//  YTHomeBannerCell.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/10.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTHomeBannerCell.h"
#import <SDCycleScrollView.h>
@interface YTHomeBannerCell()<SDCycleScrollViewDelegate>

@property(nonatomic ,strong)SDCycleScrollView *bannerView;

@property(nonatomic ,strong)NSArray *imgList;
@end
@implementation YTHomeBannerCell

- (NSArray *)imgList
{
    if (!_imgList) {
        NSMutableArray *arraM = [NSMutableArray array];
        for (int i = 0; i < 3; i++) {
            UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
            [arraM addObject:img];
        }
        _imgList = arraM.copy;
    }
    return _imgList;
}

- (void)setBanner:(YTHomeBanner *)banner
{
    _banner = banner;
    
//    self.bannerView.imageURLStringsGroup = banner.slider_img;
//    //self.bannerView.titlesGroup = banner.slider_title;
    
    //[self.bannerView ]
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    return [super initWithStyle:style reuseIdentifier:reuseIdentifier];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bannerView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds imageURLStringsGroup:self.banner.slider_img];
    self.bannerView.titlesGroup = self.banner.slider_title;
    self.bannerView.autoScrollTimeInterval = 3;
    self.bannerView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    self.bannerView.titleLabelBackgroundColor = [UIColor colorWithRed:187.0f/255.0f green:187.0f/255.0f blue:187.0f/255.0f alpha:0.8];
    [self.contentView addSubview:self.bannerView];
    self.bannerView.delegate = self;
}


#pragma mark: - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if ([self.banner.slider_url_tid[index] length] == 0) {
        return;
    }
    NSAssert(self.bannerClickBlock != nil, @"bannerClickBlock 不能为 nil");
    self.bannerClickBlock(self.banner.slider_url_tid[index]);
//    [NSNotificationCenter.defaultCenter postNotificationName:kShowArticleDetailNotification
//                                                      object:nil userInfo:@{@"ID":self.banner.slider_url_tid[index]}];
}

@end
